<template>
  <el-card class="box-card">
    <el-table
      :data="items"
    >
      <el-table-column
        align="center"
        prop="_id"
        label="id"
        width="300"
      />
      <el-table-column
        align="center"
        prop="userName"
        label="账号"
        width="150"
      />
      <el-table-column
        align="center"
        prop="pwd"
        label="密码"
        width="300"
      />
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
      >
        <template slot-scope="scope">
          <el-button
            @click="$router.push(`/admin_users/create/${scope.row._id}`)"
            type="info"
            size="medium"
          >
            编辑
          </el-button>
          <el-button
            @click="remove(scope.row)"
            type="danger"
            size="medium"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      items: []
    };
  },
  created() {
    this.fetch();
  },
  methods: {
    remove(row) {
      this.$confirm(`是否删除管理员 "${row.userName}"`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        const rs = await this.$http.delete(`rest/admin_users/${row._id}`);
        rs;
        this.$message({
          type: "success",
          message: "删除成功!"
        });
        this.fetch();
      });
    },
    async fetch() {
      const rs = await this.$http.get("rest/admin_users");
      this.items = rs.data;
    }
  }
};
</script>

<style>
</style>
